﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _04_理解事件
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student("超人", 90);
            Teacher t = new Teacher("超人他爹");
            t.GetStudent(s);
            s.SendBook();
            Console.ReadKey();
            

        }
    }

    //学生交作业给老师
    //老师批改学生的作业
    class Student
    {
        public delegate void SendScoreDelegate(object sender, EventArgs e);
        public event SendScoreDelegate SendScoreEvent;
        public int Score { get; private set; }
        public string Name { get;private set; }
        public Student(string name, int score)
        {
            this.Name = name;
            this.Score = score;
        }
        public void SendBook()
        {
            Console.WriteLine("{0}交了作业{1}分",this.Name,this.Score);
            this.SendScoreEvent(this, new EventArgs());
        }
    }
    class Teacher
    {
        public string Name { get;private set; }
        public string Score { get; private set; }
        public Teacher(string name)
        {
            this.Name = name;
        }
        public void GetStudent(Student s)
        {
            s.SendScoreEvent += new Student.SendScoreDelegate(GetBook);
            this.Score = GetScore(s.Score);
        }
        void GetBook(object sender, EventArgs e)
        {
            Console.WriteLine("{0}批阅了作业,作业为 {1}",this.Name,this.Score);
            
        }
        public string GetScore(int score)
        {
            if (score > 89)
            {
                return "优";
            }
             else if (score>79)
            {
                return "良";
            }
            else if(score>59)
            {
                return "及格";
            }

            else
            {
                return "不及格";
            }
        }
       

    }
}
